<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="类型">
              <j-dict-select-tag v-model="queryParam.type" placeholder="类型" dictCode="content_type"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="终端类型">
              <j-dict-select-tag v-model="queryParam.screen" placeholder="终端类型" dictCode="content_screen"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="活动时间">
              <a-range-picker format="YYYY-MM-DD"
                              :placeholder="['开始时间', '结束时间']"
                              @change="onTimeChange"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="地址">
                <a-input placeholder="请输入地址" v-model="queryParam.url"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <!--<a-button type="primary" icon="download" @click="handleExportXls('商城内容管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type='vertical' />
          <a @click='handleCopy(record)'>拷贝</a>

          <a-divider type="vertical"/>

          <a @click="handlePageBuilder(record)">PageBuilder</a>
          <!--<a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <cmsContentV1-modal ref="modalForm" @ok="modalFormOk"></cmsContentV1-modal>
    <cmsContentV1PageBuilder-modal ref="pageBuilerModal" @ok="modalFormOk"></cmsContentV1PageBuilder-modal>
  </a-card>
</template>

<script>
  import CmsContentV1Modal from './modules/CmsContentV1Modal'
  import CmsContentV1PageBuilderModal from './modules/CmsContentV1PageBuilderModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'

  export default {
    name: 'CmsContentV1List',
    mixins: [JeecgListMixin],
    components: {
      CmsContentV1Modal,
      CmsContentV1PageBuilderModal
    },
    data() {
      return {
        description: '商城内容管理管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: '类型',
            align: 'center',
            dataIndex: 'type_dictText'
          },
          {
            title: '终端类型',
            align: 'center',
            dataIndex: 'screen_dictText'
          },
          {
            title: '地址',
            align: 'center',
            dataIndex: 'url'
          },
          {
            title: '页面标题',
            align: 'center',
            dataIndex: 'title'
          },
          {
            title: '替换首页',
            align: 'center',
            dataIndex: 'homeFlag_dictText'
          },
          {
            title: '开启时间',
            align: 'center',
            dataIndex: 'startTime'
          },
          {
            title: '结束时间',
            align: 'center',
            dataIndex: 'endTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/cms/cmsContentV1/list',
          delete: '/cms/cmsContentV1/delete',
          deleteBatch: '/cms/cmsContentV1/deleteBatch',
          exportXlsUrl: 'cms/cmsContentV1/exportXls',
          importExcelUrl: 'cms/cmsContentV1/importExcel'
        }
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      handlePageBuilder: function (record) {
        let url = ""
        this.id = record.id

        console.log("location.host",location.host);
        url = window.location.href.substring(0,window.location.href.indexOf(location.host)) + location.host +  encodeURI('/page-builder/?id='+this.id);
        console.log("------url------"+url)
        window.open(url,'_blank');



        //-----------------------------------------
        /*this.$refs.pageBuilerModal.goUrl(record);
        this.$refs.pageBuilerModal.title = "编辑";
        this.$refs.pageBuilerModal.fullscreen = true;
        this.$refs.pageBuilerModal.switchFullscreen = true;*/
      },
      onTimeChange: function(value, dateString) {
        console.log(dateString[0], dateString[1])
        this.queryParam.endTime_begin = dateString[0]
        this.queryParam.startTime_end = dateString[1]
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>